var theLine = '';
var theSegement = '';
var listDiv = document.querySelectorAll('.listDiv');

function itemClick(obj) {
    theLine = obj.getElementsByClassName('line')[0].innerText;
    theSegement = obj.getElementsByClassName('segement')[0].innerText;
    console.log('theLine', theLine + '/' + theSegement);
    return false;
}
// comfirm页面跳转到index
function routerIndex() {
    let searchIn1 = document.getElementById('input');
    let searchIn2 = document.getElementById('input2');
    let loc1 = document.getElementById('loc1');
    let loc2 = document.getElementById('loc2');
    // if (searchIn.value == '' || loc1.value == '' || loc2.value == '') {
    //     alert('信息填写不完整！')
    // }else {
    if (searchIn2.value == '成品入库') {
        location.replace('productStorage.html?theLine=' + theLine + '&theSegement=' + theSegement);
    } else if (searchIn2.value == '包装入板') {
        location.replace('cartonPallent.html?theLine=' + theLine + '&theSegement=' + theSegement);
    } else if (searchIn2.value == 'SMT防错料') {
        location.replace('preventPN.html?theLine=' + theLine + '&theSegement=' + theSegement);
    } else if (searchIn2.value == 'B443出库') {
        location.replace('goStorage.html?theLine=' + theLine + '&theSegement=' + theSegement);
    } else if (searchIn2.value == 'B382包装上料') {
        location.replace('packagePN.html?theLine=' + theLine + '&theSegement=' + theSegement);
    }
}

function refreshBtn() {
    location.replace('site.html')
}


/**
 * 下拉搜索框
 */
var dataArr = [];
var dataList = document.getElementById('dataList');
window.onload = function() { //初始化dataArr的数据
    var childs = dataList.children; //在IE下注释也算节点,不能用于
    for (var i = 0; i < childs.length; i++) {
        dataArr.push(childs[i].innerText);
    }
    // console.log(dataArr);
}

function showDiv() {
    dataList.style.display = "";
}
// 数据过滤筛选
function filterP() {
    var e = event.target || event.srcElement;
    // console.log('e',e)
    var str = e.value;
    // console.log(str);
    dataList.innerHTML = ''; //清空div下的所有P元素
    dataArr.forEach(function(item) {
            if (item.toUpperCase().indexOf(str.toUpperCase()) != -1) {
                var p = document.createElement('p');
                var text = document.createTextNode(item);
                p.appendChild(text);
                dataList.appendChild(p);
            }
        })
        // console.log("dataList.innerHTML：" + dataList.innerHTML)
    if (dataList.innerHTML == '') {
        var p = document.createElement('p');
        var text = document.createTextNode('暂无数据');
        p.style.color = '#d7d7d7';
        p.onclick = function() { event.stopImmediatePropagation(); } //阻止事件的冒泡
        p.appendChild(text);
        dataList.appendChild(p);
    }
}

function pushInput() { //利用事件委托机制,获取点击的P源
    var e = event.target || event.srcElement;
    var input = document.getElementById('input');
    input.value = e.innerText;
    dataList.style.display = 'none';
    $('.listDiv').removeClass('listBlock');
    if (input.value.toUpperCase() == '163' || input.value.toUpperCase() == 'ABC') {
        $('.listDiv').addClass('listBlock');
        // console.log('addClass')
    }
    // console.log('input',input.value);
}

/**
 * 
 * @param {应用选择下拉} that 
 */
var dataArr2 = [];
var dataList2 = document.getElementById('dataList2');
window.onload = function() { //初始化dataArr2的数据
    var childs = dataList2.children; //在IE下注释也算节点,不能用于
    for (var i = 0; i < childs.length; i++) {
        dataArr2.push(childs[i].innerText);
    }
    // console.log(dataArr2);
}

function showDiv2() {
    dataList2.style.display = "";
}
// 数据过滤筛选
function filterP2() {
    var e = event.target || event.srcElement;
    // console.log('e',e)
    var str = e.value;
    // console.log(str);
    dataList2.innerHTML = ''; //清空div下的所有P元素
    dataArr2.forEach(function(item) {
            if (item.toUpperCase().indexOf(str.toUpperCase()) != -1) {
                var p = document.createElement('p');
                var text = document.createTextNode(item);
                p.appendChild(text);
                dataList2.appendChild(p);
            }
        })
        // console.log("dataList2.innerHTML：" + dataList2.innerHTML)
    if (dataList2.innerHTML == '') {
        var p = document.createElement('p');
        var text = document.createTextNode('暂无数据');
        p.style.color = '#d7d7d7';
        p.onclick = function() { event.stopImmediatePropagation(); } //阻止事件的冒泡
        p.appendChild(text);
        dataList2.appendChild(p);
    }
}

function pushInput2() { //利用事件委托机制,获取点击的P源
    var e = event.target || event.srcElement;
    var input2 = document.getElementById('input2');
    input2.value = e.innerText;
    dataList2.style.display = 'none';
}
// 设置点击input搜索框时弹出下拉框，点击其他部分隐藏下拉框
window.onclick = function(e) {
    if (e.target.id != 'input') {
        dataList.style.display = 'none';
    }
    if (e.target.id != 'input2') {
        dataList2.style.display = 'none';
    }
}

// 箱号配置设置为正整数
function oneInput(that) {
    if (that.value.length == 1) {
        that.value = that.value.replace(/[^1-9]/g, '')
    } else {
        that.value = that.value.replace(/\D/g, '')
    }
}

function twoInput(that) {
    if (that.value.length == 0) {
        that.value = that.value.replace(/[^0-9]/g, '')
    } else {
        that.value = that.value.replace(/\D/g, '')
    }
}

// 列表添加点击选中效果
for (let i = 0; i < listDiv.length; i++) {
    listDiv[i].onclick = function() {
        for (let j = 0; j < listDiv.length; j++) {
            listDiv[j].classList.remove('listActive')
                //  $('.listDiv').removeClass('listActive');
        }
        listDiv[i].classList.add('listActive')
            //    $(this).addClass('listActive')
    }
}


// 返回home页
function goBack() {
    location.replace('home.html');
}